package com.flong.juc.charter1;

/**
 * @Author:liangjl
 * @Date: 2020/7/4-20:24
 * @Eamil:jilongliang@sina.com
 * @Description:
 */
public class MyTest2 {
    public static void main(String[] args) throws Exception {
        MyTest2Thread test2 = new MyTest2Thread();
        test2.start();
        Thread.sleep(2000);

        test2.stopThread();
    }
}

class MyTest2Thread extends Thread {
    private boolean flag = true;

    @Override
    public void run() {
        try {
            while (flag) {
                System.out.println("time=" + System.currentTimeMillis());
                Thread.sleep(1000);
            }
            System.out.println(Thread.currentThread().getName() + "线程结束");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /**
     * 停止线程
     */
    public void stopThread() {
        flag = false;
    }
}